//
//  UserInfoPartialView.m
//  ios-supplier
//
//  Created by feynmanyuan on 15/4/19.
//  Copyright (c) 2015年 feynmanyuan. All rights reserved.
//

#import "UserInfoPartialView.h"
#import "JFBPhoneCallHelper.h"
#import "JFBDrawLineHelper.h"

@interface UserInfoPartialView(){
    UIButton *_call;
    JFBPhoneCallHelper *_callHelper;
}
@property (weak, nonatomic) IBOutlet UILabel *requireTimeLabel;
@property (weak, nonatomic) IBOutlet UILabel *userNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *userAddressLabel;
@property (weak, nonatomic) IBOutlet UIView *remarkView;
@property (weak, nonatomic) IBOutlet UILabel *remarkLabel;


@end

@implementation UserInfoPartialView

- (void)setOrder:(JFBOrderDS*)order{
    self.drawLineHelper = [[JFBDrawLineHelper alloc]init];
    NSUInteger startHeight = 0;
    
//    if( [order.orderType isEqualToString:@"undealer"]) {
//        startHeight = kOrderCellHeaderHeight;
//        CGSize requireTimeSize = [order.requireTime sizeWithAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:TextFontSizeH2]}];
//        CGFloat requireTimeY = (kOrderCellHeaderHeight - requireTimeSize.height) / 2;
//        CGFloat requireTimeX = kOrderCellSpacing;
//        CGRect requireTimeRect = CGRectMake(requireTimeX, requireTimeY, requireTimeSize.width, requireTimeSize.height);
//        self.requireTimeLabel.frame = requireTimeRect;
//        self.requireTimeLabel.text = order.requireTime;
//        
//        [self.drawLineHelper addHorizontalLine:kOrderCellSpacing y:kOrderCellHeaderHeight color:LineColorDefault width:self.bounds.size.width - kOrderCellSpacing* 2];
//    } else {
        [self.requireTimeLabel removeFromSuperview];
//    }
    NSString *userName = [NSString stringWithFormat:@"%@  %@", order.userName, order.userMobile];
    CGSize userNameSize = [userName sizeWithAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:TextFontSizeH3]}];
    CGFloat userNameY = startHeight + kOrderCellSpacing;
    CGFloat userNameX = kOrderCellMargin;
    CGRect userNameRect = CGRectMake(userNameX, userNameY, userNameSize.width, userNameSize.height);
    self.userNameLabel.text = userName;
    self.userNameLabel.frame = userNameRect;
    
//    CGSize addressSize = [order.address sizeWithAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:TextFontSizeH3]}];
    
    self.userAddressLabel.lineBreakMode = NSLineBreakByCharWrapping;
    self.userAddressLabel.numberOfLines = 0;
    CGFloat addressY = userNameY + userNameSize.height;
    CGFloat addressX = kOrderCellMargin;
    self.userAddressLabel.text = order.address;
    CGSize addressSize = [self.userAddressLabel sizeThatFits:CGSizeMake(self.bounds.size.width - 98 -kOrderCellSpacing * 2, MAXFLOAT)];
    CGRect addressRect = CGRectMake(addressX, addressY, addressSize.width, addressSize.height);
    self.userAddressLabel.frame = addressRect;
    
    if( ![order.orderType isEqualToString:@"complete"] ) {
         _callHelper = [[JFBPhoneCallHelper alloc] initWithMobile:order.userMobile color:TextColorImportButton];
        _call = [_callHelper getButton];
        [self addSubview:_call];
        CGRect callRect = CGRectMake(self.bounds.size.width - kOrderCellSpacing - 88, startHeight + kOrderCellSpacing, 88, 36);
        _call.frame = callRect;
    }
    
    
    
    if( order.remark && ![order.remark isEqualToString:@""] && ![order.remark isEqualToString:DefaultRemark] ) {
        for( UIView *v in self.remarkView.subviews ) {
            [v removeFromSuperview];
        }
        
        NSString *remask = [NSString stringWithFormat:@"备注：%@", order.remark];
        
        UILabel *label = [[UILabel alloc] init];
        [_remarkView addSubview:label];
        label.lineBreakMode = NSLineBreakByCharWrapping;
        label.numberOfLines = 0;
        [label setTextColor:TextColorRemark];
        label.font = [UIFont systemFontOfSize:TextFontSizeH3];
        label.text = remask;
        
        CGSize size = [label sizeThatFits:CGSizeMake(self.bounds.size.width - kOrderCellSpacing * 2, MAXFLOAT)];
        
        label.frame = CGRectMake(kOrderCellMargin, kOrderCellMargin / 2, size.width, size.height);
        
        self.remarkView.frame = CGRectMake(0, addressRect.origin.y + addressSize.height + kOrderCellSpacing, self.bounds.size.width, size.height + kOrderCellSpacing);
        
//        _remarkView.frame = CGRectMake(0, addressY, 0, 0);
        
        self.height = CGRectGetMaxY(_remarkView.frame) + 1;
    } else {
        [_remarkView removeFromSuperview];
        self.height = CGRectGetMaxY(self.userAddressLabel.frame) + kOrderCellSpacing;
    }
}

@end
